package client;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

public class GestioneChiavi {

	public GestioneChiavi(){
		
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}
	
	
	public void generaChiavi(){
		
		String clientKS= "clientPublicKS";
		
		char[]password = pwd.toCharArray();
		
		System.out.println("Inizio Generazione Chiavi RSA...");
		try {
			KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
			kpg.initialize(1024);
			KeyPair kp = kpg.generateKeyPair();
			
			System.out.println("Chiavi generate!");
			
			KeyStore ks = KeyStore.getInstance("JKS");
			FileInputStream fis = new FileInputStream(clientKS);
			ks.load(fis, password);
			//byte[] publicBytes = kp.getPublic().getEncoded();
			
			X509Certificate cert = (X509Certificate)ks.getCertificate(alias);
			//ks.setKeyEntry(alias, key, password, chain)
			
			
			
			
			
			
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		} catch (KeyStoreException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (CertificateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
	}
	
	public void inserisciPubKey(){
		
	}
	
	public void estraiPubKey(){
		
	}
	
	public void inserisciPrivKey(){
		
	}
	
	public void estraiPrivKey(){
		
	}

}
